import { userinfo as Userinfo } from './model/userinfo'
import { cloud, CloudDBCollection, CloudDBZoneQuery } from '@hw-agconnect/cloud-server'

const ZONE_NAME = 'GuWenDian';

export class DatabaseHelper {
  logger;
  colUserinfo: CloudDBCollection<Userinfo>

  constructor(logger) {
    this.logger = logger;
    this.colUserinfo = cloud.database({ zoneName: ZONE_NAME }).collection(Userinfo)
  }

  async insertUserinfo(userinfo: Userinfo): Promise<number|undefined>{
    try {
      // const userinfoObj = new UserInfo()
      // userinfoObj.setId(id)
      // userinfoObj.setNickName()
      // userinfoObj.setId(userId + resourceId)
      // historyObj.setBrowse_time(new Date())
      // await this.updateResourceViewCount(resourceId)
      return await this.colUserinfo.upsert(userinfo);
    } catch (error) {
      this.logger.error(`[userinfo-modify] insert collect error ${error}`);
      return -1;
    }
  }

}